var e = require("../../@babel/runtime/helpers/interopRequireDefault"), t = require("../../@babel/runtime/helpers/createForOfIteratorHelper"), a = e(require("../../@babel/runtime/regenerator")), r = require("../../@babel/runtime/helpers/asyncToGenerator"), n = e(require("../../miniprogram_npm/@vant/weapp/toast/toast")), s = getApp(), i = require("../../utils/timeUtil.js"), o = require("../../http/activityApi.js");

Page({
    distTime: 0,
    data: {
        cdBgUrl: "http://newimg.ap1983.com/prod/20220304/57fd3e9fa1b049f793f924aa34cc5ac2.jpg",
        cdItemBgUrl: "http://newimg.ap1983.com/prod/20220304/deb1b5e911e14b43ba21855b4d47f491.png",
        cdItemDotUrl: "http://newimg.ap1983.com/prod/20220304/dbfd87fb2d244661898454275592bb82.png",
        signTitleUrl: "http://newimg.ap1983.com/prod/20220304/0958fdad613c4904818546f2d854e320.png",
        giftAbleUrl: "http://newimg.ap1983.com/prod/20220304/61ae7fb8ee1b4bfa88f4de1ad79bed40.png",
        giftLockUrl: "http://newimg.ap1983.com/prod/20220304/45518525a5d04926a71e81eee9376364.png",
        giftBtnUrl: "http://newimg.ap1983.com/prod/20220304/63c1af6b08c142d886b8add7d2dd6dc0.png",
        bottomUrl: "http://newimg.ap1983.com/prod/20220304/2d21233fdf54432aa37ac475b576f1c6.png"
    },
    onLoad: function(e) {
        return r(a.default.mark(function e() {
            return a.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                  case "end":
                    return e.stop();
                }
            }, e);
        }))();
    },
    onShow: function() {
        var e = this;
        this.startTimer(), this.loadDetails(!this.data.details), s.globalData.callback = function(t) {
            "SUPER_COUPONS_SHARE_OPEND_EVENT" == t.businessType && (console.log("分享打开事件:", t.data.usedId), 
            e.loadDetails(!1));
        };
    },
    onHide: function() {
        this.stopTimer();
    },
    onUnload: function() {
        this.stopTimer();
    },
    startTimer: function() {
        var e = this;
        this.stopTimer(), this.interval = setInterval(function() {
            e.updateCd();
        }, 1e3);
    },
    stopTimer: function() {
        this.interval && (clearInterval(this.interval), this.interval = null);
    },
    updateCd: function() {
        if (this.data.details) {
            var e = new Date().getTime() + this.distTime, a = i.timeStringToLong(this.data.details.startTime), r = i.timeStringToLong(this.data.details.endTime), n = 2, s = 0, o = 0, d = 0, p = 0;
            e < a ? (n = 0, s = parseInt((a - e) / 1e3)) : e < r && (n = 1, s = parseInt((r - e) / 1e3)), 
            s > 0 && (o = parseInt(s / 60 / 60), d = parseInt((s - 3600 * o) / 60), p = s % 60), 
            this.data.actStatus >= 0 && this.data.actStatus != n && (console.log("触发刷新：", this.data.actStatus, n), 
            this.loadDetails()), this.setData({
                actStatus: n,
                h1: parseInt(o / 1e3),
                h2: parseInt(o % 1e3 / 100),
                h3: parseInt(o % 100 / 10),
                h4: parseInt(o % 10),
                m1: parseInt(d / 10),
                m2: parseInt(d % 10),
                s1: parseInt(p / 10),
                s2: parseInt(p % 10)
            });
            var u, c = t(this.data.details.productVoList);
            try {
                for (c.s(); !(u = c.n()).done; ) {
                    var l = u.value, h = i.timeStringToLong(l.usedCloseTime), g = parseInt((h - e) / 1e3);
                    g < 0 && (g = 0);
                    var f = parseInt(g / 3600), m = parseInt((g - 3600 * f) / 60), b = g % 60;
                    l.timer = "限时：" + (f > 9 ? f : "0" + f) + "小时" + (m > 9 ? m : "0" + m) + "分" + (b > 9 ? b : "0" + b) + "秒神券失效", 
                    l.cd = g;
                }
            } catch (e) {
                c.e(e);
            } finally {
                c.f();
            }
            this.setData({
                details: this.data.details
            });
        }
    },
    signItemOnTap: function(e) {
        var t = this;
        return r(a.default.mark(function r() {
            var i;
            return a.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    if (1 == e.currentTarget.dataset.status) {
                        a.next = 3;
                        break;
                    }
                    return a.abrupt("return");

                  case 3:
                    return a.prev = 3, s.showLoading(), a.next = 7, o.superCouponSign();

                  case 7:
                    i = a.sent, wx.hideLoading(), (0, n.default)({
                        selector: "#sign-toast",
                        duration: "3000",
                        mask: !0
                    }), t.setData({
                        rewards: i.data
                    }), t.loadDetails(), a.next = 18;
                    break;

                  case 14:
                    a.prev = 14, a.t0 = a.catch(3), console.log(a.t0), wx.hideLoading();

                  case 18:
                    return a.prev = 18, a.finish(18);

                  case 20:
                  case "end":
                    return a.stop();
                }
            }, r, null, [ [ 3, 14, 18, 20 ] ]);
        }))();
    },
    onShareAppMessage: function(e) {
        if ("button" == e.from) {
            var t = e.target.dataset.prod;
            return {
                title: t.shareTitle,
                path: "/pages/act-super-coupon-share/act-super-coupon-share?usedId=" + t.usedId + "&shareFrom=" + s.getUsername(),
                imageUrl: t.sharePic
            };
        }
    },
    ruleOnTap: function() {
        s.gotoPage("/pages/app-rule/app-rule?type=superCoupon");
    },
    loadDetails: function() {
        var e = arguments, t = this;
        return r(a.default.mark(function r() {
            var n, i, d;
            return a.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    return n = e.length > 0 && void 0 !== e[0] && e[0], a.prev = 1, n && s.showLoading(), 
                    a.next = 5, o.getServerTime();

                  case 5:
                    return i = a.sent, d = new Date().getTime(), t.distTime = i.data.systemTime - d, 
                    a.next = 10, o.superCouponHome();

                  case 10:
                    i = a.sent, t.setData({
                        details: i.data
                    }), t.updateCd(), a.next = 18;
                    break;

                  case 15:
                    a.prev = 15, a.t0 = a.catch(1), console.log(a.t0);

                  case 18:
                    return a.prev = 18, wx.hideLoading(), a.finish(18);

                  case 21:
                  case "end":
                    return a.stop();
                }
            }, r, null, [ [ 1, 15, 18, 21 ] ]);
        }))();
    },
    goBoxOnConfirm: function() {
        s.gotoPage("/pages/order/order");
    }
});